import {json} from "@remix-run/node";
import {authenticate} from "../shopify.server";
import axios from "axios";

export const loader = async ({ request }) => {
  // The authenticate.admin method returns a CORS method to automatically wrap responses so that extensions, which are hosted on extensions.shopifycdn.com, can access this route.
  const { cors } = await authenticate.admin(request);

  const url = new URL(request.url);
  const orderId = url.searchParams.get("orderId");
  var splitStr = orderId.split("/");
  var idNumber = parseInt(splitStr[splitStr.length - 1], 10);
  console.log('后台拿到的订单id：',idNumber)

  console.log('业务服务端开始请求')
  const response = await axios.post('http://127.0.0.1:8123/api/shopify/queryOrderBizInfo',{
    sOrderId: idNumber
  });
  const resData = response.data;
  console.log('业务服务端响应：',resData)

  return cors(json({ ...resData }));
};
